package com.example.a_buffer;

import java.io.*;

public class DeoBufferedInputStream_outputstream {
    public static void main(String[] args) {
//        method1();
        method2();
    }

    private static void method1() {
        long start = System.currentTimeMillis();
        try (
                FileInputStream fis = new FileInputStream("C:\\Users\\27408\\Desktop\\微信xcx\\02-代码\\01-基础\\.git\\refs\\tags\\19-自定义组件的使用.avi");
                FileOutputStream fos = new FileOutputStream("C:\\Users\\27408\\Desktop\\微信xcx\\02-代码\\01-基础\\.git\\refs\\tags\\2.avi");
        ) {
//            边读边写
            int len;
            while ((len = fis.read()) != -1) {
                fos.write(len);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();
        System.out.println("字节流读写耗时间为:" + (end - start));
    }

    private static void method2() {
        long start = System.currentTimeMillis();
        try (
                FileInputStream fis = new FileInputStream("C:\\Users\\27408\\Desktop\\微信xcx\\02-代码\\01-基础\\.git\\refs\\tags\\19-自定义组件的使用.avi");
                FileOutputStream fos = new FileOutputStream("C:\\Users\\27408\\Desktop\\微信xcx\\02-代码\\01-基础\\.git\\refs\\tags\\3.avi");
                BufferedInputStream bis = new BufferedInputStream(fis);
                BufferedOutputStream bos = new BufferedOutputStream(fos);
        ) {
//            边读边写

            int len;
            while ((len = bis.read()) != -1) {
                bos.write(len);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();
        System.out.println("缓冲流读写耗时间为:" + (end - start));
    }
}
